package org.springframework.core.type.classwriting;

import org.springframework.asm.Type;
import org.springframework.core.type.classreading.ServiceClassMetadataReadingVisitor;
import org.springframework.util.ClassUtils;

import cn.bonoon.kernel.annotations.services.AutoImplements;
import cn.bonoon.kernel.support.entities.Persistable;


/**
 * 实现一个接口，没有定义父类的情况
 * @author jackson
 *
 */
public class ImplementInterfaceMetadataWriter extends AbstractMetadataWriter{
//	/**
//	 * 需要被实现的接口
//	 */
//	private final Class<?> siClass;
	private final AutoImplements autoImplements;
	public ImplementInterfaceMetadataWriter(ServiceClassMetadataReadingVisitor sVisitor, Class<?> siClass, AutoImplements autoImplements) throws Throwable {
		super(sVisitor, siClass);
//		this.siClass = siClass;
		this.autoImplements = autoImplements;
		//Lcn/bonoon/kernel/support/services/AbstractService<Lcn/bonoon/entities/plugins/AccountEntity;>;Lcn/bonoon/core/plugins/AccountService;Lcn/bonoon/core/plugins/LoginService;
		String parentClassPath = Type.getDescriptor(autoImplements.parentClass()); 
		String entityClassPath = Type.getDescriptor(autoImplements.entityClass());
		String interfacesName = "L" + ClassUtils.convertClassNameToResourcePath(sVisitor.getClassName()) + ";";
		this.signature = parentClassPath.substring(0, parentClassPath.length() - 1) + "<" + entityClassPath + ">;" + interfacesName;
	}
	
	@Override
	protected String parseParentName() {
		// TODO 根据接口的类型，使用相应的父类
		// 这里还需要知道该接口所需要处理的实体是什么类型的，是否是树型结构的数据
		return autoImplements.parentClass().getName();
	}

	@Override
	protected Class<? extends Persistable> parseEntityClass() {
		return autoImplements.entityClass();
	}

	@Override
	protected Class<?> parseParentClass() {
		return autoImplements.parentClass();
	}

}
